﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddConfig.aspx.cs" Inherits="background.Manager.Config.SiteConfig.AddConfig" %>

<!DOCTYPE html>
<% 
    if(string.IsNullOrEmpty(Request["actionType"])) { Response.Write("缺少actionType参数"); return; }
    if(!new Regex("^(add|update)$").IsMatch(Request["actionType"])) { Response.Write("actionType参数：只能是add或update"); return; }
    if(Request["actionType"].ToString()=="update") {
        if(string.IsNullOrEmpty(Request["id"])) { Response.Write("缺少id参数"); return; }
        if(!new Regex("^\\d+$").IsMatch(Request["id"])) { Response.Write("id参数错误"); return; }
    }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../Styles/index.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../../Scripts/layer/layer.js"></script>

</head>
<body>
    <div class="top">
        <strong>系统属性配置</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <!--表单提交-->
        <div>
            <table border="0" cellpadding="0" cellspacing="0" class="table">
                <tr>
                    <th>调用拼音</th>
                    <td>
                        <input type="text" id="pyName" class="text" value="" /><i>* 系统将此字段作为调用凭证</i></td>
                </tr>
                <tr>
                    <th>属性名字</th>
                    <td>
                        <input type="text" id="title" class="text" value="" /><i>*</i></td>
                </tr>
                <tr>
                    <th>编辑器</th>
                    <td>
                        <input type="text" id="inputType" class="text" value="" /><i>* text（普通文本），full（富文本）</i></td>
                </tr>

                <tr>
                    <th>文本宽高</th>
                    <td>
                        <input type="text" id="input_w_h" class="text" value="" /><i>文本框的宽高 200,20，没有则不填</i></td>
                </tr>
                <tr>
                    <th>分组</th>
                    <td>
                        <input type="text" id="group" class="text" value="" /><i></i></td>
                </tr>
                <tr>
                    <th>排序</th>
                    <td>
                        <input type="text" id="order" class="text" value="0" /><i>数字越小越靠前，此排序影响后台配置前后显示顺序</i></td>
                </tr>
                <tr>
                    <th style="vertical-align: top">功能描述</th>
                    <td>
                        <textarea class="text" id="desc" style="height: 50px; width: 276px"></textarea><i></i></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" class="sbtn" value="保存" onclick="submit_save()" /></td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        function submit_save() {
            var _pyName = $("#pyName"),
                _title = $("#title"),
                _inputType = $("#inputType"),
                _input_w_h = $("#input_w_h"),
                _group = $("#group"),
                _desc = $("#desc"),
                _order = $("#order");
            if ($.trim(_pyName.val()).length == 0) { layer.msg("请输入调用拼音"); _pyName.focus(); return; }
            if ($.trim(_title.val()).length == 0) { layer.msg("请输入属性名字"); _title.focus(); return; }
            if ($.trim(_inputType.val()).length == 0) { layer.msg("请输入编辑器"); _inputType.focus(); return; }
            var data = {
                action: "<%=Request["actionType"]%>",
                pyName: _pyName.val(),
                title: _title.val(),
                inputType: _inputType.val(),
                input_w_h: _input_w_h.val(),
                desc: _desc.val(),
                group: _group.val(),
                order: _order.val()
            }
            if ('<%=Request["actionType"]%>' == 'update') {
                data["id"] = '<%=Request["id"]%>';
            }
            $.post("../Action/SiteConfig.ashx", data, function (ret) {
                if (ret) {
                    layer.msg("恭喜您保存成功", { icon: 1, time: 2000 }, function () { window.location.href="ConfigList.aspx" })
                } else {
                    layer.msg("对不起保存失败", { icon: 2, time: 2000 })
                }
            })
        }
        function loadData() {
            $.getJSON("../Action/SiteConfig.ashx", { action: "getInfo", id: '<%=Request["id"]%>' }, function (resultJson) {
                var json = resultJson[0];
                $("#pyName").val(json.pyName);
                $("#title").val(json.title);
                $("#inputType").val(json.inputType);
                $("#input_w_h").val(json.input_w_h);
                $("#group").val(json.group);
                $("#desc").val(json.desc);
                $("#order").val(json.order);
            })
        }
        <%=string.IsNullOrEmpty(Request["id"])?"":"loadData();"%>
    </script>
    <!--#include file='../../Include/footer.html'-->
</body>
</html>
